<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Driver;
use Illuminate\Http\Request;

class DriverController extends Controller
{
    /**
     * 获取司机列表
     */
    public function index()
    {
        $drivers = Driver::where('status', 1)->get();
        
        return response()->json([
            'code' => 200,
            'message' => '获取成功',
            'data' => $drivers
        ]);
    }
    
    /**
     * 根据司机姓名获取车型和车牌信息
     */
    public function getDriverInfo(Request $request)
    {
        $name = $request->input('name');
        
        if (!$name) {
            return response()->json([
                'code' => 400,
                'message' => '缺少司机姓名参数'
            ]);
        }
        
        $driver = Driver::where('name', $name)
            ->where('status', 1)
            ->first();
            
        if (!$driver) {
            return response()->json([
                'code' => 404,
                'message' => '司机信息不存在'
            ]);
        }
        
        return response()->json([
            'code' => 200,
            'message' => '获取成功',
            'data' => [
                'car_type' => $driver->car_type,
                'license_plate' => $driver->license_plate,
                'phone' => $driver->phone
            ]
        ]);
    }
}
